package com.freesky.quartz.task;

import com.freesky.biz.psbc.domain.TPsbcLotteryTicket;
import com.freesky.biz.psbc.mapper.PsbcLotteryTicketMapper;
import com.freesky.biz.psbc.service.PsbcCommService;
import com.freesky.common.core.domain.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 彩票抽奖平台定时数据同步
 */
@Component("psbcLotteryTicket")
public class PsbcLotteryTicketTask {

    private static final Logger logger = LoggerFactory.getLogger(PsbcLotteryTicketTask.class);

    @Autowired
    private PsbcLotteryTicketMapper psbcLotteryTicketMapper;

    @Autowired
    private PsbcCommService psbcCommService;

    public void taskProcess() {
        logger.info("psbcLotteryTicketTask task start");
        List<TPsbcLotteryTicket> psbcLotteryTicketList = psbcLotteryTicketMapper.loadUnPushList();
        for(TPsbcLotteryTicket psbcLotteryTicket : psbcLotteryTicketList){
            AjaxResult ajaxResult = psbcCommService.commService(psbcLotteryTicket.getOrderNo(),psbcLotteryTicket.getCpnCode(),"01");
            if(ajaxResult.isSuccess()){
                psbcLotteryTicketMapper.updatePushFlag(psbcLotteryTicket.getId(),"1");
            } else {
                psbcLotteryTicketMapper.updatePushFlag(psbcLotteryTicket.getId(),"2");
            }
        }



    }

}
